/*
Autor: Alexander Savochkin, 2010
New BSD License
*/

#include "FakeIO.h"
#include "Exception.h"
#include <boost/tokenizer.hpp>
#include <boost/lexical_cast.hpp>

using boost::tokenizer;
using boost::lexical_cast;
using boost::bad_lexical_cast;

namespace SRCLF
{
namespace IO
{
	void FakeInput::adminCommand(const string& command, string& result)
	{
	}

	void FakeInput::controlCommand(const string& command, string& result)
	{
		tokenizer<> tok(command);
		tokenizer<>::iterator tok_it = tok.begin();
		if( *tok_it == "set" )
		{
			++tok_it;
			try {
				value = lexical_cast<double>(*tok_it);
			}
			catch(bad_lexical_cast &)
			{
				throw ParseException("number expected");
			}
			if(++tok_it != tok.end())
				throw ParseException("end of command expected");
		}
		else //parse error
			throw ParseException("'set' command expected");		
	}

	void FakeInput::infoCommand(string& command, string& result)
	{
	}

	void FakeOutput::adminCommand(const string& command, string& result)
	{
	}

	void FakeOutput::controlCommand(const string& command, string& result)
	{
		tokenizer<> tok(command);
		tokenizer<>::iterator tok_it = tok.begin();
		if( *tok_it == "set" )
		{
			++tok_it;
			try {
				value = lexical_cast<double>(*tok_it);
			}
			catch(bad_lexical_cast &)
			{
				throw ParseException("number expected");
			}
			if(++tok_it != tok.end())
				throw ParseException("end of command expected");
		}
		else //parse error
			throw ParseException("'set' command expected");
	}

	void FakeOutput::infoCommand(string& command, string& result)
	{
	}
} //namespace IO
} //namespace SRCLF
